<?php
namespace app\controllers\api\post;

use fate\http\Request;
use app\models\Posts;
use app\libs\LibUser;

// 不验证用户
class ListController extends \fate\web\PureController {

    public function run() {
        $req = Request::getInstance();
        $strUid = $req->getQueryString('uid');
        $p = $req->getQueryString('page');
        $pageSize = $req->getQueryString('pagesize');
        $showReiew = $req->getQueryString('review');

        $uid = LibUser::decodeId($strUid);

        if(!is_numeric($pageSize)) {
            $pageSize = 10;
        }

        if(!is_numeric($uid)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }
        if(!is_numeric($p)) {
            $p = 1;
        }

        // user center req
        $where = 'status=1 and uid=' . $uid;
        if('1' === $showReiew) {
            $where = 'status<>2 and uid=' . $uid;
        }

        $posts = new Posts();
        $total = $posts->count($where);
        $ret = $posts->getListByPage(
            'id,uid,tags,title,thumb,brief,views,post_time,status',
            $where, $p, $pageSize);

        $this->ajaxReturn([
            'page_size' => $pageSize,
            'current' => $p,
            'total' => $total,
            'data' => $ret
        ]);
    }

}
